package com.shxc.smarttrade.community.fragment;


import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.shxc.smarttrade.R;
import com.shxc.smarttrade.base.BaseFragment;
import com.shxc.smarttrade.community.adapter.AndroidMasterAdapter;
import com.shxc.smarttrade.community.model.MasterSimpleModel;
import com.shxc.smarttrade.currency.activity.WebActivity;
import com.shxc.smarttrade.info.Contents;

import org.xchris.view.annotation.ContentView;
import org.xchris.view.annotation.ViewInject;

import java.util.ArrayList;
import java.util.List;

/**
 * 社区 - 大师
 */
@ContentView(R.layout.recycler)
public class AndroidMasterFragment extends BaseFragment {

    @ViewInject(R.id.recyclerview)
    RecyclerView recyclerview;

    private List<MasterSimpleModel> list;
    private AndroidMasterAdapter adapter;

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        list = new ArrayList();
        list.add(new MasterSimpleModel("第一章",R.mipmap.dsxy_img_1, Contents.H5 +"/newpages/college-detail-1.html"));
        list.add(new MasterSimpleModel("第二章",R.mipmap.dsxy_img_2, Contents.H5 +"/newpages/college-detail-2.html"));
        list.add(new MasterSimpleModel("第三章",R.mipmap.dsxy_img_3, Contents.H5 +"/newpages/college-detail-3.html"));
        list.add(new MasterSimpleModel("第四章",R.mipmap.dsxy_img_4, Contents.H5 +"/newpages/college-detail-4.html"));
        list.add(new MasterSimpleModel("第五章",R.mipmap.dsxy_img_5, Contents.H5 +"/newpages/college-detail-5.html"));
        list.add(new MasterSimpleModel("第六章",R.mipmap.dsxy_img_6, Contents.H5 +"/newpages/college-detail-6.html"));
        list.add(new MasterSimpleModel("第七章",R.mipmap.dsxy_img_7, Contents.H5 +"/newpages/college-detail-7.html"));

        recyclerview.setLayoutManager(new LinearLayoutManager(mContext));
        adapter = new AndroidMasterAdapter(mContext,list,handler);
        recyclerview.setAdapter(adapter);
    }

    Handler handler = new Handler() {
        @Override
        public void dispatchMessage(Message msg) {
            switch (msg.what) {
                case 1:
                    //點擊跳轉
                    MasterSimpleModel model = (MasterSimpleModel) msg.obj;
                    bundle.putString("title",model.getTitle());
                    bundle.putString("url",model.getUrl());
                    JumpTo(WebActivity.class,bundle);
//                    MobclickAgent.onEvent(getContext(), "transaction_detail");//友盟统计该点击事件发生次数
                    break;
            }
            super.dispatchMessage(msg);
        }
    };
}
